﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.supply
{
    public partial class ListBalance : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                DataSet ds_pro = new Maticsoft.BLL.project().GetListSumNumsInfo(" uid=" + user_id);

                this.GridView1.DataSource = ds_pro;
                this.GridView1.DataBind();


            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_balance")
            {
                string projectId = e.CommandArgument.ToString();

                Response.Redirect("BalanceDetail.aspx?projectId="+projectId);
            }
        }

        protected void btn_reload_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;

            Bind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType ==  DataControlRowType.DataRow)
            {
                Label lbl_beComplatedTime = e.Row.FindControl("lbl_beComplatedTime") as Label;//竣工日期
                LinkButton lbn_balance = e.Row.FindControl("lbn_balance") as LinkButton;//竣工结算

                if (!string.IsNullOrEmpty(lbl_beComplatedTime.Text))
                {
                    DateTime beComplatedTime = DateTime.Parse(lbl_beComplatedTime.Text);


                    if (beComplatedTime.CompareTo(DateTime.Now) > 0)//竣工日期大于当前日期
                    {
                        lbn_balance.Enabled = false;
                    }
                    else
                    {
                        lbn_balance.Enabled = true;
                    }
                }
                else
                {
                    lbn_balance.Enabled = false;
                }
            }
        }

      
    }
}